<?php

namespace App\Admin\Controllers;

use App\AdminUser;
use App\Post;
use Illuminate\Http\Request;

class PostController extends Controller
{
    //列表
    public function index()
    {
        $posts = Post::withoutGlobalScope('avaiable')->where('status', 0)->OrderBy('created_at', 'desc')->paginate(10);
        return view('admin.post.index', compact('posts'));
    }

    //审核
    public function status(Post $post)
    {
        $this->validate(\request(), [
            'status' => 'required | in : -1, 1',
        ]);

        $post->status = \request('status');
        $post->save();

        return [
          'code' => 200,
          'msg' => '审核成功'
        ];
    }
}
